import {deleteAction, getAction, postAction, downFile, getFileAccessHttpUrl} from '@/api/request'
import {getLodop} from './LodopFuncs'

export const LodopMixin = {

    data() {
        return {
            printUrl: "/api/ac/subsistence/lodopServiceImpl/print",
            printStatusUrl: "/api/ac/subsistence/lodopServiceImpl/updatePrintStatus",
            Loading: false,
        }
    },
    methods: {
        printStatus(h) {
            if (h.cellValue) {
                if (h.cellValue == 0) {
                    return "未打印"
                } else {
                    return "已打印"
                }
            }
        },
        commonPrint(param, tabNum, ss21001Id, dbzb0100) {
            this.Loading = true;
            postAction(this.printUrl, param).then((res) => {
                if (res.data.errcode != 0) {
                    this.$Message.error(res.data.errmsg);
                } else {
                    this.loadLodop(res.data.data, tabNum, ss21001Id, dbzb0100);
                }
            }).finally(() => {
                this.Loading = false;
            })
        },
        loadLodop(list, tabNum, ss21001Id, dbzb0100) {
            console.log(">>>>>>>>>>>>>>>>>>>>>>>")
            var LODOP = getLodop();
            console.log(LODOP)
            var that = this;
            for (var i in list) {
                var type = list[i].type;
                var top = list[i].top;
                var left = list[i].left;
                var width = list[i].width;
                var height = list[i].height;
                var name = list[i].name;
                var style1 = list[i].style1;
                var style2 = list[i].style2;
                var style3 = list[i].style3;
                if ("PRINT_INITA" == type) {
                    LODOP.PRINT_INITA(top, left, width, height, "TEMPLATE");
                } else if ("ADD_PRINT_TEXT" == type) {
                    LODOP.ADD_PRINT_TEXT(top, left, width, height, name);
                } else if ("SET_PRINT_STYLEA" == type) {
                    LODOP.SET_PRINT_STYLEA(style1, style2, style3);
                }
            }
            if (LODOP.CVERSION) {
                CLODOP.On_Return = function (TaskID, Value) {
                    if (Value) {
                        that.tipShow(tabNum, ss21001Id, dbzb0100);
                    } else {
                    }
                };
                LODOP.PREVIEW();
                return;
            }
        },
        tipShow(tabNum, ss21001Id, dbzb0100) {
            this.$Modal.confirm({
                title: '是否打印成功？',
                onOk: () => {
                    this.finishPrint(tabNum, ss21001Id, dbzb0100);
                }
            })
        },
        finishPrint(tabNum, ss21001Id, dbzb0100) {
            this.Loading = true;
            var param = new Object();
            param.ss21001Id = ss21001Id;
            param.dbzb0100 = dbzb0100;
            param.tabNum = tabNum;
            postAction(this.printStatusUrl, param).then((res) => {
                if (res.data.errcode != 0) {
                    this.$Message.error(res.data.errmsg);
                } else {
                    this.$Message.success("打印成功!");
                    this.$emit('finishCertificate');
                }
            }).finally(() => {
                this.Loading = false;
            })
        }
    }
}
